package cn.wolfcode.wolf2w.result;


import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.List;

@Getter
@Setter
@ToString
public class PageResult<T> {
	private int currentPage = 1;
	private int prevPage;
	private int nextPage;
	private int totalPage;

	private int totalCount;
	private int pageSize = 3;
	private List<T> data;

	public PageResult(int currentPage, int totalCount, int pageSize, List<T> data) {
		this.currentPage = currentPage;
		this.totalCount = totalCount;
		this.pageSize = pageSize;
		this.data = data;

		if(this.totalCount <= this.pageSize){
			this.currentPage = 1;
			this.totalPage = 1;
			this.prevPage  = 1;
			this.nextPage = 1;
		}

		this.totalPage = this.totalCount % this.pageSize == 0
				? this.totalCount / this.pageSize : this.totalCount / this.pageSize + 1;
		this.prevPage = this.currentPage - 1 >= 1 ? this.currentPage - 1 : 1;
		this.nextPage = this.currentPage + 1 <= this.totalPage ? this.currentPage + 1 : this.totalPage;
	}
}
